package com.example.oauth.rest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/redirect")
public class RedirectController {
    
    @GetMapping("/test1")
    public String code(){
        return "redirect:https://www.wxg123.com/?code=123";
    }
    
    @GetMapping("/test2")
    public void test2(HttpServletResponse response) throws IOException {
        response.sendRedirect("https://www.wxg123.com/?code=123");
    }
    
    @GetMapping("/info")
    @ResponseBody
    public String info(){
        return "hello redirect";
    }
    
    @GetMapping("/test3")
    public void test3(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.sendRedirect(request.getContextPath()+"/redirect/info");
    }

    /**
     * http://localhost:9060/redirect/test4?host=https://www.wxg123.com
     * @param host
     * @param response
     * @throws IOException
     */
    @GetMapping("/test4")
    public void test4(String host,HttpServletResponse response) throws IOException {
        response.sendRedirect(host+"?code=123");
    }
}
